<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //       实现一个电子钟：都是汉字中文 显示年月日 时分秒

      // 1.10-20 之间 十一 、 十二、十三 。。。。

      // 20 以后 二十一 二十二 二十三 ....
      // 3.20,30,40 50... 二十 三十 四十

      // 4.不需要考虑 60以上
      function getYear(year) {
        var arr = [
          "零",
          "一",
          "二",
          "三",
          "四",
          "五",
          "六",
          "七",
          "八",
          "九",
          "十",
        ];
        var a = parseInt(year / 1000);
        var b = parseInt((year % 1000) / 100);
        var c = parseInt((year % 1000) / 10);
        var d = parseInt(year % 10);
        return `${arr[a]}${arr[b]}${arr[c]}${arr[d]}`;
      }

      function getMonth(month) {
        var arr = [
          "一",
          "二",
          "三",
          "四",
          "五",
          "六",
          "七",
          "八",
          "九",
          "十",
          "十一",
          "十二",
        ];
        var a = month;
        return `${arr[a]}`;
      }

      function getHours(time) {
        var arr = [
          "零",
          "一",
          "二",
          "三",
          "四",
          "五",
          "六",
          "七",
          "八",
          "九",
          "十",
        ];
        if (time <= 10) {
          return arr[time];
        } else if (time % 10 == 0) {
          var a = parseInt(time / 10);
          return `${arr[a]}十`;
        } else if (time > 10 && time < 20) {
          var b = time % 10;
          return `十${arr[b]}`;
        } else {
          var a = parseInt(time / 10);
          var b = time % 10;
          return `${arr[a]}十${arr[b]}`;
        }
      }

      function fn() {
        var time = new Date();
        var year = time.getFullYear();
        var month = time.getMonth();
        var date = time.getDate();
        var hour = time.getHours();
        var minute = time.getMinutes();
        var second = time.getSeconds();
        var str = `现在时间是${getYear(year)}年${getMonth(month)}月${getHours(
          date
        )}日${getHours(hour)}时${getHours(minute)}分${getHours(second)}秒`;

        document.body.innerHTML = str;
      }
      setInterval(function () {
        fn();
      }, 1000);
    </script>
  </body>
</html>
